<template>
  <div class="box">
    <navigation-bar></navigation-bar>
    <sprint-text @toParentAddLog="receiveFromChild($event)" :sendData="result.toChild" :resCode="result.response" :sendGround="result.toChildGround" :fixLog="result.fixLog"></sprint-text>
  </div>
</template>
<script>
import navigationBar from '@/components/navigationBar'
import sprintText from '@/components/sprintText'
import { _addLog, _getGroupList, _getSprintList, _getLogDetails, _fixLog } from '../common/api'
export default {
  components: {
    navigationBar,
    sprintText
  },
  data () {
    return {
      result: {
        receiveData: [],
        toChild: {'name': 'hahah'},
        toChildGround: {'ground': 'I am ground'},
        response: '请求信息提示',
        fixLog: '',
        groupId: '',
        sprintId: ''
      }
    }
  },
  created () {
    this.getGroupList()
    this.getSprintList()
    this.fixLog()
  },
  methods: {
    getData (data) {
      this.receiveData.push(data)
      console.log(data)
      _addLog(data).then(res => {
        console.log(res)
      }).catch(e => {
        console.log(e)
      })
    },
    getGroupList () {
      // var that = this
      _getGroupList().then(res => {
        this.$set(this.result, 'toChildGround', res.filter(item => item.groupStatus !== 0))
      })
      // console.log(that.result.toChildGround)
    },
    getSprintList () {
      _getSprintList().then(res => {
        // console.log(res)
        this.$set(this.result, 'toChild', res.filter(item => item.groupStatus !== 0))
      })
    },
    receiveFromChild (data) {
      console.log(data)
      console.log(data.status)
      if (data.status === '修改日志') {
        this.fixLoged(data)
      } else {
        this.addLog(data)
      }
    },
    fixLoged (data) {
      console.log(data)
      var body = {
        'logId': this.$route.query.logId,
        'logName': data.logName,
        'logContent': data.content,
        'logPublishtime': data.logPublishtime,
        'logAttachment': '',
        'logStatus': '1',
        'logOperator': data.promulgatorName,
        'groupId': data.groupId,
        'sprintId': data.sprintId
      }
      console.log(body)
      _fixLog(body).then((res) => {
        console.log('修改日志详情')
        console.log(res)
      })
    },
    addLog (data) {
      var year = new Date().getFullYear()
      var month = new Date().getMonth() + 1
      var day = new Date().getDate()
      var logPublishtime = year + '-' + month + '-' + day
      console.log(logPublishtime)
      console.log(data)
      var body = {
        'logName': data.logName,
        'logContent': data.content,
        'logPublishtime': logPublishtime,
        'logOperator': data.promulgatorName,
        'groupId': data.groupId,
        'sprintId': data.sprintId
      }
      console.log(body)
      _addLog(body).then(res => {
        console.log('录入日志回调')
        console.log(res)
        console.log(this.result.response)
        // this.$set(this.result, 'response', res)
      })
    },
    fixLog () {
      var logId = this.$route.query.logId
      console.log(logId)
      _getLogDetails({logId: logId}).then((res) => {
        console.log(res)
        this.$set(this.result, 'fixLog', res)
        console.log(this.result.fixLog)
      })
    }
  }
}
</script>

<style scoped lang="sass">
</style>
